package com.example.doctorsystem.controller;

import com.example.doctorsystem.model.Announcement;
import com.example.doctorsystem.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/announcements")
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    // 发布公告
    @PostMapping
    public String addAnnouncement(@RequestBody Announcement announcement) {
        int result = announcementService.addAnnouncement(announcement);
        return result > 0 ? "公告发布成功" : "公告发布失败";
    }

    // 获取所有公告
    @GetMapping
    public List<Announcement> getAllAnnouncements() {
        return announcementService.getAllAnnouncements();
    }

    // 删除公告（可选）
    @DeleteMapping("/{id}")
    public String deleteAnnouncement(@PathVariable int id) {
        int result = announcementService.deleteAnnouncementById(id);
        return result > 0 ? "删除成功" : "删除失败";
    }
}
